package com.lizard.schedule.ui.activity.base;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.lizard.schedule.BuildConfig;
import com.lizard.schedule.log.ScheduleLog;
import com.lizard.schedule.manager.umeng.UmengManager;

/**
 * 项目中所有FragmentAcitivity继承自本类
 */
public class BaseFragmentAcitivity extends FragmentActivity {

    private final String TAG = getClass().getSimpleName();

    private final String TAG_LIFE = TAG + " life";

    /**
     * activity 生命周期log是否打印
     */
    private final boolean mLiftLogAble = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        logLife("onCreate(Bundle savedInstanceState)");
    }



    @Override
    protected void onStart() {
        super.onStart();
        logLife("onStart()");
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        logLife("onPostCreate(Bundle savedInstanceState)");
    }

    @Override
    protected void onResume() {
        super.onResume();
        logLife("onResume()");
        UmengManager.getInstance().onResume(this);
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        logLife("onPostResume()");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        logLife("onRestart()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        logLife("onPause()");
        UmengManager.getInstance().onPause(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        logLife("onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        logLife("onDestroy()");
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        logLife("onNewIntent(Intent intent)");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        logLife("onRestoreInstanceState(Bundle savedInstanceState)");
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        logLife("onSaveInstanceState(Bundle outState)");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        logLife("onConfigurationChanged(Configuration newConfig)");
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        logLife("onLowMemory()");
    }

    /**
     * 生命周期log输出
     */
    private void logLife(String actLife){
        if(mLiftLogAble){
            ScheduleLog.v(TAG_LIFE, actLife);
        }
    }

}
